/**
$Id: WsgiService.hpp 3096 2010-07-06 07:21:14Z Bear $

Copyright (c) 2010 Nuwa Information Co., Ltd, and individual contributors.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice,
     this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright
     notice, this list of conditions and the following disclaimer in the
     documentation and/or other materials provided with the distribution.

  3. Neither the name of Nuwa Information nor the names of its contributors
     may be used to endorse or promote products derived from this software
     without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

$Author: Bear $
$Date: 2010-07-06 15:21:14 +0800 (星期二, 06 七月 2010) $
$Revision: 3096 $
*/

#ifndef __WSGISERVICE_HEADER__
#define __WSGISERVICE_HEADER__

#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>

#include <pion/PionLogger.hpp>
#include <pion/net/WebService.hpp>

#include "pion-glue.hpp"

namespace pion {  // begin namespace pion
namespace plugins {  // begin namespace plugins

/**
Service that provides WSGI ability to pion web server.
*/
class WsgiService : public pion::net::WebService
{
public:

 /**
 Constructor.
 */
 WsgiService();

 /**
 Destructor.
 */
 virtual ~WsgiService();

/**
@name Overwrited methods.
*/
//@{

 virtual void setOption(const std::string& name, const std::string& value);

 virtual void start(void);
 
 virtual void stop(void);

 virtual void operator()(pion::net::HTTPRequestPtr& request,
                         pion::net::TCPConnectionPtr& tcp_conn);
//@}

public:

 /**
 Accessor for name.

 @return Name.
 */
 const std::string& getName()
 {
  return name;
 }

 /**
 Accessor for port.

 @return Port.
 */
 const std::string& getPort()
 {
  return port;
 }

protected:

 /// Logger.
 pion::PionLogger logger;

 /// Mutex used to log info, only used if info=1.
 boost::mutex infoMutex;

/**
@name Options.
*/
//@{

 /// Server name.
 std::string name;

 /// Server port.
 std::string port;

#ifdef _PYTHON

#else

 /// Python module.
 std::string module;

 /// WSGI handler in module.
 std::string app;

#endif

 /// Show request and response result information.
 bool info;

//@}

};

} // end namespace plugins
} // end namespace pion

#endif
